﻿#include "GlobalManager.h"
#include <QSqlDatabase>
#include <QDebug>
#include "qqml.h"
#include "ChatTools/TransferProxy.h"

GlobalManager::GlobalManager() {
    QSqlDatabase sqlBase(QSqlDatabase::addDatabase("QSQLITE"));
    sqlBase.setDatabaseName("./qtDb.db");
    if(!sqlBase.open()) {
        qDebug() << "open sql fail!!";
    }else {
        qDebug() << "all tables " << sqlBase.tables();
    }
    qmlRegisterType<ClientDataRecordSqlTableModel>("Top", 1, 0, "ClientDataRecordSqlTableModel");
    qmlRegisterType<TcpServeManager>("Top", 1, 0, "TcpServeManager");
    qmlRegisterType<NewTcpClient>("Top", 1, 0, "NewTcpClient");
    qmlRegisterType<TransferProxy>("Top", 1, 0, "TransferProxy");

    //只有数据库打开以后才能创建数据库 打开失败他也会自己创一个数据库d
    clientDataRecordSqlTableModel = new ClientDataRecordSqlTableModel;
}

GlobalManager *GlobalManager::GetInstance() {
    static GlobalManager it;
    return &it;
}
